package zyAll.animalParadise;

import java.util.Scanner;

public class Test {
    public static void modify()throws Exception{
        Scanner sca = new Scanner(System.in);
        System.out.println("是否要修改数据:按0进行操作,其他任意数字键退出:");
        int num = sca.nextInt();
        if (num == 0){
            System.out.println("请输入猫的名称:");
            String name = sca.next();
            System.out.println("请输入猫腿的条数:");
            int number = sca.nextInt();
            if (number != 4){
                try {
                    throw new Exception("猫的腿数只能是四只");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }else {
            return;
        }
    }

    public static void main(String[] args) {
        System.out.println("动物名字"+"\t\t腿的条数"+"\t\t动物叫");
        Animal[] animals = {
                new Cat("加菲猫"),
                new Duck("唐小鸭"),
                new Dolphin("海豚奇奇")
                };

        Cat cat = (Cat) animals[0];
        if (cat instanceof Terrestrial){
            cat.show();
            cat.leg(4);
            cat.shout();
        }

        Duck duck = (Duck) animals[1];
        if (duck instanceof Terrestrial){
            duck.show();
            duck.leg(2);
            duck.shout();
        }

        Dolphin dolphin = (Dolphin) animals[2];
        if (dolphin instanceof Terrestrial){
            dolphin.show();
            dolphin.leg(0);
            dolphin.shout();
        }

        try {
            modify();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
